GBML manual / Stacks

stack_length

How many items target currently holds - 0 for an empty stack, up to target's own declared capacity once it is full.

Syntax

stack_length(target) -> int

Arguments

NameType
targetstack

Returns

int

Description

How many items target currently holds - 0 for an empty stack, up to target's own declared capacity (/// @capacity, or 8 if untagged) once it is full.

This is how many items are IN target right now, not its capacity - a common use is checking whether there is still room before pushing, or showing a depth counter on the HUD.

Example

/// @type {stack<int>}
var history = [1, 2, 3];
var depth = stack_length(history); // 3
A real capture - an empty stack, stack_length reading 0A real capture - an empty stack, stack_length reading 0
A real capture - an empty stack, stack_length reading 0
The same stack after filling it with the example's three moves - stack_length now 3The same stack after filling it with the example's three moves - stack_length now 3
The same stack after filling it with the example's three moves - stack_length now 3

On the GBA

Just the vector's size() - O(1), identical to list_length.

See also: stack_pushstack_popstack_clearstack_emptyData containers